#ifndef COMMON_H
#define COMMON_H
class tcp_socket;
#include <tcp_socket.h>
class local_socket;
#include <local_socket.h>
#include <QWeakPointer>
#include "QReadWriteLock"
class M_Socket;
#include "m_socket.h"
#include "caculate_task.h"
#include <QThread>
#include <QMutex>
struct SQLData{
    QString SQL_ip;
    QString SQL_Sname;
    QString Sql_Username;
    QString SQL_Password;
};
struct MessageSocket{

    Socket_type Stype;
    tcp_socket *t_socket=NULL;
    local_socket *l_socket=NULL;
};

struct HandleMessage{
    HandleMessage(QString id,QString type,QString data,MessageSocket M_socket,emit_type te_ype)
    {
        this->id=id;
        this->type=type;
        this->data=data;
        this->M_socket=M_socket;
        this->te_ype=te_ype;

    }
    QString id;
    QString type;
    QString data;
    MessageSocket M_socket;
    emit_type te_ype;

};

struct LocalSocket_UnSendData
{
    LocalSocket_UnSendData(QString id,QString type,QString data,emit_type emittype,QString sockettype)
    {
        this->id=id;
        this->type=type;
        this->data=data;
        this->emittype=emittype;
        this->sockettype=sockettype;
    }
    QString id;
    QString type;
    QString data;
    emit_type emittype;
    QString sockettype;
};


class Common
{
public:
    Common();
    static QMap  <tcp_socket*,QSharedPointer<M_Socket>>  tcp_server_SocketMap;          //t_socketMAP
    static QReadWriteLock   tcp_server_SocketMapLock;                                   //t_socket读写锁
    static QMap<local_socket*,QSharedPointer<M_Socket>> localSocket_Map;                //l_socketMAP
    static QReadWriteLock   localSocket_MapLock;                                        //l_socket读写锁
    static QSharedPointer<M_Socket> GetLocal_Socket();                                  //获取一个Localsocket
    static SQLData mysql_data;                                                          //数据库信息
    static QReadWriteLock   SQL_Lock;                                                   //数据库信息读写锁
    static QMap<QString,QSharedPointer<Caculate_Task>>     CaculateTask;                //计算任务列表
    static QReadWriteLock   CaculateTask_lock;                                          //计算任务锁
    static QSharedPointer<M_Socket> GetFree_Caculatenode();                             //获取空闲计算节点
    static QSharedPointer<Decomposition_Task>   GetFree_Decomposition_Task();           //获取未完成的分解任务
    static QList<LocalSocket_UnSendData>      Localsocket_unsenddata;                   //本地socket未发送的任务
    static QReadWriteLock   Localsocket_unsenddataLock;                                 //本地socket未发送任务读写锁
    static QMap<QString,QString>                Dll_Md5;                                //本地DLL文件对应MD5值
    static QReadWriteLock   Dll_Md5lock;                                                //本地DLL文件对应MD5值读写锁
    static QStringList      SQL_write;                                                  //sql批量写入
    static QMutex           SQL_writeLock;                                              //sql写入锁
    static QStringList      Logdata;                                                    //日志内容
    static QReadWriteLock   LogdataLock;                                                //日志锁

    static QReadWriteLock   ConfigureLock;                                              //配置锁
    static bool             Log_Open;                                                   //日志是否开启
    static int              Log_Size;                                                   //日志保存大小
    static int              TcpPort;                                                    //TCP监听端口
    static int              TcpHandleThreadNum;                                         //TCP处理线程数量
    static QString          LocalPort;                                                  //Local监听端口
    static QString          SQL_IP;                                                     //数据库IP
    static QString          SQL_DBname;                                                 //数据库名称
    static QString          SQL_UserName;                                               //数据库账号
    static QString          SQL_Password;                                               //数据库密码
    static int              Handle_Count;                                               //处理线程数量
    static int              distribution_multiple;                                      //分配任务倍数
};

#endif // COMMON_H
